<template>
  <div>
    <!-- 面包屑区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>  
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card shadow="hover">
      <!-- 搜索和添加商品区域 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入要搜索的商品订单"  clearable >
            <template slot="append"><el-button type="primary" icon="el-icon-search"></el-button></template>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="orderList" stripe  border style="width: 100%">
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号"> </el-table-column>
        <el-table-column prop="order_price" width="95px" label="订单价格"> </el-table-column>
        <el-table-column prop="pay_status" width="95px" label="是否付款"> 
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status===1">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" width="95px"  label="是否发货"> </el-table-column>
        <el-table-column  label="下单时间" prop="create_time" width="150px">
          <template slot-scope="scope">
            {{scope.row.create_time | dataFormat}}
          </template>
        </el-table-column>
        <el-table-column  label="操作" width="130px"> 
        <!-- 操作 -->
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" size="mini"  @click="editLocation(scope.row)"></el-button>
            <el-button type="success" icon="el-icon-location" size="mini"  @click="showProgress(scope.row)"></el-button>
          </template>
        </el-table-column>
      </el-table>
       <!-- 分页区域 -->
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          background  >
      </el-pagination>
      <!-- 修改地址对话框 -->
      <el-dialog title="修改地址" :visible.sync="editAddrdialogFormVisible" @close="editDialogClose">
        <el-form :model="editForm" ref="editFormRef" :rules="editFormRules" label-width="100px">
          <el-form-item label="省市区/县" >
          <!-- 级联地区选择器 -->
            <el-cascader
              v-model="editFormRules.address1"
              :options="citydata"
              >
            </el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" >
            <el-input v-model="editForm.address2"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="editAddrdialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="editAddrdialogFormVisible = false">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 物流进度 -->
      <el-dialog title="物流进度" :visible.sync="showProgressVisible" width="50%">
        <el-timeline>
          <el-timeline-item v-for="(timeItem, index) in postTime.data" :key="index"
            :timestamp="timeItem.time">
             {{timeItem.context}}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>

    </el-card>
    
  </div>
</template>
<script>
import postTime from './posttime'
import citydata from './citydata'
import {orderListReq,addressReq} from '../../networks/order'
export default {
  name:'Order',
  data() {
    return {
      queryInfo:{
        query:'',
        pagesize:10,
        pagenum:1,
      },
      orderList:[],
      total:0,
      // 对话框组件的显示与隐藏
      editAddrdialogFormVisible:false,
      showProgressVisible:false,
      // 表单数据对象
      editForm:{
        address1:[],
        address2:'',
      },
      // 表单规则对象
      editFormRules:{
        address1:[ { required: true, message: '请选择省市区/县', trigger: 'blur' },],
        address2:[ { required: true, message: '请填写详细地址', trigger: 'blur' },],
      },
      citydata:citydata,
      postTime,
    }
  },
  created() {
    this.getOrderList();
  },
  methods: {
    //获取订单列表
    getOrderList(){
      orderListReq(this.queryInfo).then(res=>{
        console.log(res,"orderListReq");
        if(res.meta.status!==200) return this.$message.error("获取订单列表失败！");
        // 保存数据
        this.orderList=res.data.goods;
        this.total=res.data.total;

      })
    },
    handleSizeChange(newSize){
      this.queryInfo.pagesize=newSize;
      this.getOrderList();
    },
    handleCurrentChange(newPage){
      this.queryInfo.pagenum=newPage;
      this.getOrderList();
    },
    // 修改地址
    editLocation(row){
      this.editAddrdialogFormVisible=true;
    },
    editDialogClose(){
      this.$refs.editFormRef.resetFields();
    },
    showProgress(){
      // 请求数据
      addressReq("/kuaidi/1106975712662").then(res=>{
        console.log(res,"addressReq");
      })
      this.showProgressVisible=true;
      console.log(this.postTime);
    }
    
  },
}
</script>
<style scoped>
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item.css';
.el-cascader{
  width: 100%;
}
</style>